/*
 * MP3_Beaney - The MP3 Tag Editor is a free ID3-Tag Editor
 * Copyright (C) 2012 Bernhard Teismann, André Seipelt, Steffen Gruschka, Imanuel Rohlfing
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details. 
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
package uInterface;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.table.DefaultTableModel;
import model.MP3Exception;
import model.MP3Management;

/**
 * Panel for Control Elements of MP3 Tag Editing.
 *
 * @author Steffen Gruschka
 * @author Bernhard Teismann
 * @author André Seipelt
 * @author Imanuel Rohlfing
 * @version 1.0
 */
public class Step3 extends javax.swing.JPanel {

    /**
     * Creates new form Step3
     */
    public Step3(){
        initComponents();
        extendedInit();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        step3TrackChooser = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        playButtoPanel = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        step3TextTrack = new javax.swing.JTextField();
        step3TextTitle = new javax.swing.JTextField();
        step3TextArtist = new javax.swing.JTextField();
        step3TextAlbum = new javax.swing.JTextField();
        step3TextGenre = new javax.swing.JTextField();
        step3TextYear = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        step3TextareaComment = new javax.swing.JTextArea();
        step3LabelTrack = new javax.swing.JLabel();
        step3LabelTitle = new javax.swing.JLabel();
        step3LabelArtist = new javax.swing.JLabel();
        step3LabelAlbum = new javax.swing.JLabel();
        step3LabelGenre = new javax.swing.JLabel();
        step3LabelYear = new javax.swing.JLabel();
        step3LabelComment = new javax.swing.JLabel();
        artistForAllButtonPanel = new javax.swing.JPanel();
        albumForAllButtonPanel = new javax.swing.JPanel();
        genreForAllButtonPanel = new javax.swing.JPanel();
        yearForAllButtonPanel = new javax.swing.JPanel();
        commentForAllButtonPanel = new javax.swing.JPanel();
        openGraficPanel = new javax.swing.JPanel();
        forAllGraficPanel = new javax.swing.JPanel();

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 100, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 100, Short.MAX_VALUE)
        );

        setBackground(new java.awt.Color(255, 255, 255));
        setPreferredSize(new java.awt.Dimension(987, 400));

        step3TrackChooser.setFont(new java.awt.Font("Lucida Grande", 0, 14)); // NOI18N
        step3TrackChooser.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        step3TrackChooser.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(step3TrackChooser);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setEnabled(false);
        jPanel2.setFocusable(false);
        jPanel2.setMaximumSize(new java.awt.Dimension(146, 146));
        jPanel2.setMinimumSize(new java.awt.Dimension(146, 146));
        jPanel2.setPreferredSize(new java.awt.Dimension(135, 135));

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 0, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 0, Short.MAX_VALUE)
        );

        playButtoPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        org.jdesktop.layout.GroupLayout playButtoPanelLayout = new org.jdesktop.layout.GroupLayout(playButtoPanel);
        playButtoPanel.setLayout(playButtoPanelLayout);
        playButtoPanelLayout.setHorizontalGroup(
            playButtoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 62, Short.MAX_VALUE)
        );
        playButtoPanelLayout.setVerticalGroup(
            playButtoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 64, Short.MAX_VALUE)
        );

        jPanel7.setBackground(new java.awt.Color(255, 255, 255));
        jPanel7.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        step3TextTrack.setMaximumSize(new java.awt.Dimension(6, 20));
        step3TextTrack.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                step3TextTrackKeyReleased(evt);
            }
        });
        jPanel7.add(step3TextTrack, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 0, 226, -1));

        step3TextTitle.setMaximumSize(new java.awt.Dimension(6, 20));
        step3TextTitle.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                step3TextTitleKeyReleased(evt);
            }
        });
        jPanel7.add(step3TextTitle, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 30, 226, -1));

        step3TextArtist.setMaximumSize(new java.awt.Dimension(6, 20));
        step3TextArtist.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                step3TextArtistKeyReleased(evt);
            }
        });
        jPanel7.add(step3TextArtist, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 60, 200, -1));

        step3TextAlbum.setMaximumSize(new java.awt.Dimension(6, 20));
        step3TextAlbum.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                step3TextAlbumKeyReleased(evt);
            }
        });
        jPanel7.add(step3TextAlbum, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 90, 200, -1));

        step3TextGenre.setMaximumSize(new java.awt.Dimension(6, 20));
        step3TextGenre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                step3TextGenreKeyReleased(evt);
            }
        });
        jPanel7.add(step3TextGenre, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 120, 200, -1));

        step3TextYear.setMaximumSize(new java.awt.Dimension(6, 20));
        step3TextYear.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                step3TextYearKeyReleased(evt);
            }
        });
        jPanel7.add(step3TextYear, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 150, 200, -1));

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        step3TextareaComment.setColumns(20);
        step3TextareaComment.setRows(2);
        step3TextareaComment.setTabSize(7);
        step3TextareaComment.setMaximumSize(new java.awt.Dimension(220, 30));
        step3TextareaComment.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                step3TextareaCommentKeyReleased(evt);
            }
        });
        jScrollPane2.setViewportView(step3TextareaComment);

        jPanel7.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 180, 200, 44));

        step3LabelTrack.setBackground(new java.awt.Color(255, 255, 255));
        step3LabelTrack.setFont(new java.awt.Font("Rockwell", 0, 13)); // NOI18N
        step3LabelTrack.setText("Nummer");
        jPanel7.add(step3LabelTrack, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 0, -1, -1));

        step3LabelTitle.setBackground(new java.awt.Color(255, 255, 255));
        step3LabelTitle.setFont(new java.awt.Font("Rockwell", 0, 13)); // NOI18N
        step3LabelTitle.setText("Titel");
        jPanel7.add(step3LabelTitle, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, -1, -1));

        step3LabelArtist.setBackground(new java.awt.Color(255, 255, 255));
        step3LabelArtist.setFont(new java.awt.Font("Rockwell", 0, 13)); // NOI18N
        step3LabelArtist.setText("Künstler");
        jPanel7.add(step3LabelArtist, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, -1));

        step3LabelAlbum.setBackground(new java.awt.Color(255, 255, 255));
        step3LabelAlbum.setFont(new java.awt.Font("Rockwell", 0, 13)); // NOI18N
        step3LabelAlbum.setText("Album");
        jPanel7.add(step3LabelAlbum, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, -1, -1));

        step3LabelGenre.setBackground(new java.awt.Color(255, 255, 255));
        step3LabelGenre.setFont(new java.awt.Font("Rockwell", 0, 13)); // NOI18N
        step3LabelGenre.setText("Genre");
        jPanel7.add(step3LabelGenre, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 118, -1, -1));

        step3LabelYear.setBackground(new java.awt.Color(255, 255, 255));
        step3LabelYear.setFont(new java.awt.Font("Rockwell", 0, 13)); // NOI18N
        step3LabelYear.setText("Jahr");
        jPanel7.add(step3LabelYear, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 150, -1, -1));

        step3LabelComment.setBackground(new java.awt.Color(255, 255, 255));
        step3LabelComment.setFont(new java.awt.Font("Rockwell", 0, 13)); // NOI18N
        step3LabelComment.setText("Kommentar");
        jPanel7.add(step3LabelComment, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 180, -1, -1));

        artistForAllButtonPanel.setBackground(new java.awt.Color(255, 0, 0));
        artistForAllButtonPanel.setToolTipText("");
        artistForAllButtonPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        artistForAllButtonPanel.setPreferredSize(new java.awt.Dimension(20, 20));

        org.jdesktop.layout.GroupLayout artistForAllButtonPanelLayout = new org.jdesktop.layout.GroupLayout(artistForAllButtonPanel);
        artistForAllButtonPanel.setLayout(artistForAllButtonPanelLayout);
        artistForAllButtonPanelLayout.setHorizontalGroup(
            artistForAllButtonPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );
        artistForAllButtonPanelLayout.setVerticalGroup(
            artistForAllButtonPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );

        jPanel7.add(artistForAllButtonPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 60, -1, -1));

        albumForAllButtonPanel.setBackground(new java.awt.Color(255, 0, 0));
        albumForAllButtonPanel.setToolTipText("");
        albumForAllButtonPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        albumForAllButtonPanel.setPreferredSize(new java.awt.Dimension(20, 20));

        org.jdesktop.layout.GroupLayout albumForAllButtonPanelLayout = new org.jdesktop.layout.GroupLayout(albumForAllButtonPanel);
        albumForAllButtonPanel.setLayout(albumForAllButtonPanelLayout);
        albumForAllButtonPanelLayout.setHorizontalGroup(
            albumForAllButtonPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );
        albumForAllButtonPanelLayout.setVerticalGroup(
            albumForAllButtonPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );

        jPanel7.add(albumForAllButtonPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 90, -1, -1));

        genreForAllButtonPanel.setBackground(new java.awt.Color(255, 0, 0));
        genreForAllButtonPanel.setToolTipText("");
        genreForAllButtonPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        genreForAllButtonPanel.setPreferredSize(new java.awt.Dimension(20, 20));

        org.jdesktop.layout.GroupLayout genreForAllButtonPanelLayout = new org.jdesktop.layout.GroupLayout(genreForAllButtonPanel);
        genreForAllButtonPanel.setLayout(genreForAllButtonPanelLayout);
        genreForAllButtonPanelLayout.setHorizontalGroup(
            genreForAllButtonPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );
        genreForAllButtonPanelLayout.setVerticalGroup(
            genreForAllButtonPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );

        jPanel7.add(genreForAllButtonPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 120, -1, -1));

        yearForAllButtonPanel.setBackground(new java.awt.Color(255, 0, 0));
        yearForAllButtonPanel.setToolTipText("");
        yearForAllButtonPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        yearForAllButtonPanel.setPreferredSize(new java.awt.Dimension(20, 20));

        org.jdesktop.layout.GroupLayout yearForAllButtonPanelLayout = new org.jdesktop.layout.GroupLayout(yearForAllButtonPanel);
        yearForAllButtonPanel.setLayout(yearForAllButtonPanelLayout);
        yearForAllButtonPanelLayout.setHorizontalGroup(
            yearForAllButtonPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );
        yearForAllButtonPanelLayout.setVerticalGroup(
            yearForAllButtonPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );

        jPanel7.add(yearForAllButtonPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 150, -1, -1));

        commentForAllButtonPanel.setBackground(new java.awt.Color(255, 0, 0));
        commentForAllButtonPanel.setToolTipText("");
        commentForAllButtonPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        commentForAllButtonPanel.setPreferredSize(new java.awt.Dimension(20, 20));

        org.jdesktop.layout.GroupLayout commentForAllButtonPanelLayout = new org.jdesktop.layout.GroupLayout(commentForAllButtonPanel);
        commentForAllButtonPanel.setLayout(commentForAllButtonPanelLayout);
        commentForAllButtonPanelLayout.setHorizontalGroup(
            commentForAllButtonPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );
        commentForAllButtonPanelLayout.setVerticalGroup(
            commentForAllButtonPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );

        jPanel7.add(commentForAllButtonPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 180, -1, -1));

        openGraficPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        openGraficPanel.setPreferredSize(new java.awt.Dimension(20, 20));

        org.jdesktop.layout.GroupLayout openGraficPanelLayout = new org.jdesktop.layout.GroupLayout(openGraficPanel);
        openGraficPanel.setLayout(openGraficPanelLayout);
        openGraficPanelLayout.setHorizontalGroup(
            openGraficPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );
        openGraficPanelLayout.setVerticalGroup(
            openGraficPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );

        forAllGraficPanel.setToolTipText("");
        forAllGraficPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        forAllGraficPanel.setPreferredSize(new java.awt.Dimension(20, 20));

        org.jdesktop.layout.GroupLayout forAllGraficPanelLayout = new org.jdesktop.layout.GroupLayout(forAllGraficPanel);
        forAllGraficPanel.setLayout(forAllGraficPanelLayout);
        forAllGraficPanelLayout.setHorizontalGroup(
            forAllGraficPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );
        forAllGraficPanelLayout.setVerticalGroup(
            forAllGraficPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 20, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(43, 43, 43)
                                .add(playButtoPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(forAllGraficPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(jPanel1Layout.createSequentialGroup()
                                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(openGraficPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(11, 11, 11)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(openGraficPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(18, 18, 18)
                                .add(playButtoPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(forAllGraficPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 637, Short.MAX_VALUE)
                .add(18, 18, 18)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 361, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(0, 26, Short.MAX_VALUE))
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void extendedInit(){
        playLabel = new JLabel();
        selectGrfic = new JLabel();
        graficforAll = new JLabel();
        artistforAll = new JLabel();
        albumforAll = new JLabel();
        genreforAll = new JLabel();
        yearforAll = new JLabel();
        commentforAll = new JLabel();
        selectGrfic.setToolTipText("Lade neues Cover für diese Datei!");
        artistforAll.setToolTipText("Künstler für Alle übernehmen!");
        graficforAll.setToolTipText("Cover für Alle übernehmen!");
        albumforAll.setToolTipText("Album für Alle übernehmen!");
        genreforAll.setToolTipText("Genre für Alle übernehmen!");
        yearforAll.setToolTipText("Jahr für Alle übernehmen!");
        commentforAll.setToolTipText("Kommentar für Alle übernehmen!");

        MouseListener mouseListener = new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent me){
                try{
                    if (me.getSource().equals(genreforAll)){
                        for (int i = 0; i < manager.size(); i++){
                            manager.get(i).setGenre(step3TextGenre.getText());
                        }
                    }
                    if (me.getSource().equals(yearforAll)){
                        for (int i = 0; i < manager.size(); i++){
                            manager.get(i).setRelease(step3TextYear.getText());
                            step3TrackChooser.setValueAt(step3TextYear.getText(), i, 4);
                            updateUI();
                        }
                    }
                    if (me.getSource().equals(albumforAll)){
                        for (int i = 0; i < manager.size(); i++){
                            manager.get(i).setAlbum(step3TextAlbum.getText());
                            step3TrackChooser.setValueAt(step3TextAlbum.getText(), i, 3);
                            updateUI();
                        }
                    }
                    if (me.getSource().equals(artistforAll)){
                        for (int i = 0; i < manager.size(); i++){
                            manager.get(i).setArtist(step3TextArtist.getText());
                            step3TrackChooser.setValueAt(step3TextArtist.getText(), i, 2);
                            updateUI();
                        }
                    }

                    if (me.getSource().equals(commentforAll)){
                        for (int i = 0; i < manager.size(); i++){
                            manager.get(i).setComment(step3TextareaComment.getText());
                        }
                    }
                    if (me.getSource().equals(graficforAll)){
                        System.out.println("Grafic all");
                        //byte[] grafic = manager.get(step3TrackChooser.getSelectedRow()).getCover();
                        File grafic = manager.get(step3TrackChooser.getSelectedRow()).getCover();
                        for (int i = 0; i < manager.size(); i++){
                            manager.get(i).setCover(grafic);
                        }
                        updateSelection();
                    }
                }catch (MP3Exception e){
                    JOptionPane.showMessageDialog(null, e.get(), Messages.HEADLINE_ERR, JOptionPane.ERROR_MESSAGE, createIcon(Messages.IMAGE_FAULT));
                }
                if (me.getSource().equals(selectGrfic)){
                    choseGrafic();
                }
                if (me.getSource().equals(playLabel)){
                    playButtonEvent();
                }
            }

            @Override
            public void mousePressed(MouseEvent me){
            }

            @Override
            public void mouseReleased(MouseEvent me){
            }

            @Override
            public void mouseEntered(MouseEvent me){
            }

            @Override
            public void mouseExited(MouseEvent me){
            }
        };

        albumforAll.addMouseListener(mouseListener);
        genreforAll.addMouseListener(mouseListener);
        artistforAll.addMouseListener(mouseListener);
        yearforAll.addMouseListener(mouseListener);
        graficforAll.addMouseListener(mouseListener);
        selectGrfic.addMouseListener(mouseListener);
        playLabel.addMouseListener(mouseListener);
        commentforAll.addMouseListener(mouseListener);

        playLabel.setIcon(createIcon(Messages.IMAGE_PLAY));
        graficforAll.setIcon(createIcon(Messages.IMAGE_FORALL));
        genreforAll.setIcon(createIcon(Messages.IMAGE_FORALL));
        artistforAll.setIcon(createIcon(Messages.IMAGE_FORALL));
        albumforAll.setIcon(createIcon(Messages.IMAGE_FORALL));
        yearforAll.setIcon(createIcon(Messages.IMAGE_FORALL));
        selectGrfic.setIcon(createIcon(Messages.IMAGE_ADDIMAGE));
        commentforAll.setIcon(createIcon(Messages.IMAGE_FORALL));

        playLabel.setBounds(0, 0, 60, 60);
        graficforAll.setBounds(0, 0, 20, 20);
        albumforAll.setBounds(0, 0, 20, 20);
        artistforAll.setBounds(0, 0, 20, 20);
        yearforAll.setBounds(0, 0, 20, 20);
        genreforAll.setBounds(0, 0, 20, 20);
        selectGrfic.setBounds(0, 0, 20, 20);
        commentforAll.setBounds(0, 0, 20, 20);

        playLabel.setVisible(true);
        graficforAll.setVisible(true);
        albumforAll.setVisible(true);
        yearforAll.setVisible(true);
        artistforAll.setVisible(true);
        genreforAll.setVisible(true);
        selectGrfic.setVisible(true);
        commentforAll.setVisible(true);

        playButtoPanel.setBackground(Color.WHITE);
        albumForAllButtonPanel.setBackground(Color.white);
        artistForAllButtonPanel.setBackground(Color.white);
        yearForAllButtonPanel.setBackground(Color.white);
        genreForAllButtonPanel.setBackground(Color.white);
        openGraficPanel.setBackground(Color.white);
        commentForAllButtonPanel.setBackground(Color.white);
        forAllGraficPanel.setBackground(Color.white);


        playButtoPanel.add(playLabel);
        albumForAllButtonPanel.add(albumforAll);
        artistForAllButtonPanel.add(artistforAll);
        yearForAllButtonPanel.add(yearforAll);
        genreForAllButtonPanel.add(genreforAll);
        openGraficPanel.add(selectGrfic);
        forAllGraficPanel.add(graficforAll);
        commentForAllButtonPanel.add(commentforAll);
    }

    /**
     * Setter for the MainInterface.
     * <p/>
     * @param mainInt the MainInterface
     */
    public void setMainInterface(MainInterface mainInt){
        main = mainInt;
    }

    private void choseGrafic(){
        JFileChooser choose = new JFileChooser();

        choose.setDialogTitle("Bilddatei auswaelen");
        choose.setFileSelectionMode(JFileChooser.FILES_ONLY);
        choose.setFileFilter(new FileFilter() {

            @Override
            public String getDescription(){
                return ".jpg .png .gif .jpeg Files";
            }

            @Override
            public boolean accept(File f){
                return f.isDirectory()
                        || f.getName().toLowerCase().endsWith(".jpg")
                        || f.getName().toLowerCase().endsWith(".png")
                        || f.getName().toLowerCase().endsWith(".gif")
                        || f.getName().toLowerCase().endsWith(".jpeg");
            }
        });
        if (choose.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){
            try{
                manager.get(step3TrackChooser.getSelectedRow()).setCover(new File(choose.getSelectedFile().getAbsolutePath()));
                updateSelection();
            }catch (MP3Exception e){
                JOptionPane.showMessageDialog(null, e.get(), Messages.HEADLINE_ERR, JOptionPane.ERROR_MESSAGE, createIcon(Messages.IMAGE_FAULT));
            }
        }
    }

    /**
     * Updates the Table and Player for leave the Step with Back Button
     */
    public void leaveTableBack(){
        step3TrackChooser.clearSelection();
        step3TrackChooser.removeAll();
        step3TrackChooser.setModel(new DefaultTableModel());
        if (manager.isMP3Playing()){
            playButtonEvent();
            playLabel.setIcon(createIcon(Messages.IMAGE_PLAY));

        }
    }

    /**
     * Updates the Table and Player for leave the Step with Next Button
     */
    public void leaveTableFront(){
        if (manager.isMP3Playing()){
            playButtonEvent();
            playLabel.setIcon(createIcon(Messages.IMAGE_PLAY));
        }
    }

    /**
     * Rebuilds the Table and updates the Frame
     */
    public void updateTable(){
        DefaultTableModel model = new DefaultTableModel(
                new Object[][]{},
                new String[]{
                    Messages.TABLE_NUMBER, Messages.TABLE_NAME, Messages.TABLE_ARTIST, Messages.TABLE_ALBUM, Messages.TABLE_YEAR
                }) {

            boolean[] canEdit = new boolean[]{
                false, false, false, false, false
            };

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex){
                return canEdit[columnIndex];
            }
        };

        step3TrackChooser.getTableHeader().setReorderingAllowed(false);
        step3TrackChooser.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent lse){
                if (lse.getValueIsAdjusting()){
                    return;
                }
                TableChoiseSelectionListener(lse);
            }
        });
        for (int i = 0; i < manager.size(); i++){
            try{
                model.insertRow(i, new Object[]{manager.get(i).getTrack(),
                                                manager.get(i).getTitle(),
                                                manager.get(i).getArtist(),
                                                manager.get(i).getAlbum(),
                                                manager.get(i).getRelease()});
            }catch (MP3Exception e){
                JOptionPane.showMessageDialog(null, e.get(), Messages.HEADLINE_ERR, JOptionPane.ERROR_MESSAGE, createIcon(Messages.IMAGE_FAULT));
            }
        }
        step3TrackChooser.setModel(model);

        step3TrackChooser.getColumn(Messages.TABLE_NUMBER).setPreferredWidth(10);
        step3TrackChooser.getColumn(Messages.TABLE_NAME).setPreferredWidth(100);
        step3TrackChooser.getColumn(Messages.TABLE_ARTIST).setPreferredWidth(100);
        step3TrackChooser.getColumn(Messages.TABLE_ALBUM).setPreferredWidth(80);
        step3TrackChooser.getColumn(Messages.TABLE_YEAR).setPreferredWidth(50);
        step3TrackChooser.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        step3TrackChooser.changeSelection(0, 0, true, false);
        step3TrackChooser.updateUI();
    }

    /**
     * Setter for manager.
     * <p/>
     * @param manage MP3Manager
     */
    public void setMP3Manager(MP3Management manage){
        manager = manage;
    }

    /**
     * This Method checks the state form player and change it
     */
    public void playButtonEvent(){
        if (!manager.isMP3Playing()){
            try{
                manager.playMP3(step3TrackChooser.getSelectedRow());
                playLabel.setIcon(createIcon(Messages.IMAGE_STOP));
            }catch (MP3Exception e){
                JOptionPane.showMessageDialog(null, e.get(), Messages.HEADLINE_ERR, JOptionPane.ERROR_MESSAGE, createIcon(Messages.IMAGE_FAULT));
            }
        }else{
            try{
                manager.stopMP3(step3TrackChooser.getSelectedRow());
            }catch (MP3Exception e){
                JOptionPane.showMessageDialog(null, e.get(), Messages.HEADLINE_ERR, JOptionPane.ERROR_MESSAGE, createIcon(Messages.IMAGE_FAULT));
            }
            playLabel.setIcon(createIcon(Messages.IMAGE_PLAY));
        }
    }

    private void TableChoiseSelectionListener(ListSelectionEvent evt){
        updateSelection();
    }

    private void updateSelection(){
        int selectedRow = step3TrackChooser.getSelectedRow();
        if (selectedRow != -1){
            try{
                jPanel2.removeAll();
                jPanel2.setBackground(Color.WHITE);
                BufferedImage image = manager.get(selectedRow).getCoverAsImage();
                JLabel label;
                if (image != null){
                    label = new JLabel(new ImageIcon(image));
                }else{
                    label = new JLabel(createIcon(Messages.IMAGE_NOIMAGE));
                }
                label.setHorizontalAlignment(JLabel.CENTER);
                jPanel2.setLayout(null);
                jPanel2.repaint();
                org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
                jPanel2.setLayout(jPanel2Layout);
                jPanel2Layout.setHorizontalGroup(
                        jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup().add(0, 0, Short.MAX_VALUE).add(label)));
                jPanel2Layout.setVerticalGroup(
                        jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING).add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup().add(0, 0, Short.MAX_VALUE).add(label)));

                step3TextAlbum.setText(manager.get(selectedRow).getAlbum());
                step3TextArtist.setText(manager.get(selectedRow).getArtist());
                step3TextGenre.setText(manager.get(selectedRow).getGenre());
                step3TextYear.setText(manager.get(selectedRow).getRelease());
                step3TextTitle.setText(manager.get(selectedRow).getTitle());
                step3TextTrack.setText(manager.get(selectedRow).getTrack());
                step3TextareaComment.setText(manager.get(selectedRow).getComment());
                updateUI();
            }catch (MP3Exception e){
                JOptionPane.showMessageDialog(null, e.get(), Messages.HEADLINE_ERR, JOptionPane.ERROR_MESSAGE, createIcon(Messages.IMAGE_FAULT));
            }
        }

    }

    private void step3TextTitleKeyReleased(java.awt.event.KeyEvent evt){//GEN-FIRST:event_step3TextTitleKeyReleased
        try{
            manager.get(step3TrackChooser.getSelectedRow()).setTitle(step3TextTitle.getText());
            step3TrackChooser.setValueAt(step3TextTitle.getText(), step3TrackChooser.getSelectedRow(), 1);
            updateUI();
        }catch (MP3Exception e){
            JOptionPane.showMessageDialog(null, e.get(), Messages.HEADLINE_ERR, JOptionPane.ERROR_MESSAGE, createIcon(Messages.IMAGE_FAULT));
        }
    }//GEN-LAST:event_step3TextTitleKeyReleased

    private void step3TextTrackKeyReleased(java.awt.event.KeyEvent evt){//GEN-FIRST:event_step3TextTrackKeyReleased
        try{
            manager.get(step3TrackChooser.getSelectedRow()).setTrack(step3TextTrack.getText());
            step3TrackChooser.setValueAt(step3TextTrack.getText(), step3TrackChooser.getSelectedRow(), 0);
            updateUI();
        }catch (MP3Exception e){
            JOptionPane.showMessageDialog(null, e.get(), Messages.HEADLINE_ERR, JOptionPane.ERROR_MESSAGE, createIcon(Messages.IMAGE_FAULT));
        }
    }//GEN-LAST:event_step3TextTrackKeyReleased

    private void step3TextArtistKeyReleased(java.awt.event.KeyEvent evt){//GEN-FIRST:event_step3TextArtistKeyReleased
        try{
            manager.get(step3TrackChooser.getSelectedRow()).setArtist(step3TextArtist.getText());
            step3TrackChooser.setValueAt(step3TextArtist.getText(), step3TrackChooser.getSelectedRow(), 2);
            updateUI();
        }catch (MP3Exception e){
            JOptionPane.showMessageDialog(null, e.get(), Messages.HEADLINE_ERR, JOptionPane.ERROR_MESSAGE, createIcon(Messages.IMAGE_FAULT));
        }
    }//GEN-LAST:event_step3TextArtistKeyReleased

    private void step3TextAlbumKeyReleased(java.awt.event.KeyEvent evt){//GEN-FIRST:event_step3TextAlbumKeyReleased
        try{
            manager.get(step3TrackChooser.getSelectedRow()).setAlbum(step3TextAlbum.getText());
            step3TrackChooser.setValueAt(step3TextAlbum.getText(), step3TrackChooser.getSelectedRow(), 3);
            updateUI();
        }catch (MP3Exception e){
            JOptionPane.showMessageDialog(null, e.get(), Messages.HEADLINE_ERR, JOptionPane.ERROR_MESSAGE, createIcon(Messages.IMAGE_FAULT));
        }
    }//GEN-LAST:event_step3TextAlbumKeyReleased

    private void step3TextGenreKeyReleased(java.awt.event.KeyEvent evt){//GEN-FIRST:event_step3TextGenreKeyReleased
        try{
            manager.get(step3TrackChooser.getSelectedRow()).setGenre(step3TextGenre.getText());
        }catch (MP3Exception e){
            JOptionPane.showMessageDialog(null, e.get(), Messages.HEADLINE_ERR, JOptionPane.ERROR_MESSAGE, createIcon(Messages.IMAGE_FAULT));
        }
    }//GEN-LAST:event_step3TextGenreKeyReleased

    private void step3TextYearKeyReleased(java.awt.event.KeyEvent evt){//GEN-FIRST:event_step3TextYearKeyReleased
        try{
            manager.get(step3TrackChooser.getSelectedRow()).setRelease(step3TextYear.getText());
            step3TrackChooser.setValueAt(step3TextYear.getText(), step3TrackChooser.getSelectedRow(), 4);
            updateUI();
        }catch (MP3Exception e){
            JOptionPane.showMessageDialog(null, e.get(), Messages.HEADLINE_ERR, JOptionPane.ERROR_MESSAGE, createIcon(Messages.IMAGE_FAULT));
        }
    }//GEN-LAST:event_step3TextYearKeyReleased

    private void step3TextareaCommentKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_step3TextareaCommentKeyReleased
        try{
            manager.get(step3TrackChooser.getSelectedRow()).setComment(step3TextareaComment.getText());
            updateUI();
        }catch (MP3Exception e){
            JOptionPane.showMessageDialog(null, e.get(), Messages.HEADLINE_ERR, JOptionPane.ERROR_MESSAGE, createIcon(Messages.IMAGE_FAULT));
        }
    }//GEN-LAST:event_step3TextareaCommentKeyReleased

    private ImageIcon createIcon(String path){
        java.net.URL imgUrl = getClass().getResource(path);
        if (imgUrl != null){
            return new ImageIcon(imgUrl);
        }else{
            return null;
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel albumForAllButtonPanel;
    private javax.swing.JPanel artistForAllButtonPanel;
    private javax.swing.JPanel commentForAllButtonPanel;
    private javax.swing.JPanel forAllGraficPanel;
    private javax.swing.JPanel genreForAllButtonPanel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPanel openGraficPanel;
    private javax.swing.JPanel playButtoPanel;
    private javax.swing.JLabel step3LabelAlbum;
    private javax.swing.JLabel step3LabelArtist;
    private javax.swing.JLabel step3LabelComment;
    private javax.swing.JLabel step3LabelGenre;
    private javax.swing.JLabel step3LabelTitle;
    private javax.swing.JLabel step3LabelTrack;
    private javax.swing.JLabel step3LabelYear;
    private javax.swing.JTextField step3TextAlbum;
    private javax.swing.JTextField step3TextArtist;
    private javax.swing.JTextField step3TextGenre;
    private javax.swing.JTextField step3TextTitle;
    private javax.swing.JTextField step3TextTrack;
    private javax.swing.JTextField step3TextYear;
    private javax.swing.JTextArea step3TextareaComment;
    private javax.swing.JTable step3TrackChooser;
    private javax.swing.JPanel yearForAllButtonPanel;
    // End of variables declaration//GEN-END:variables
    private MP3Management manager;
    private JLabel playLabel;
    private JLabel graficforAll;
    private JLabel albumforAll;
    private JLabel yearforAll;
    private JLabel genreforAll;
    private JLabel artistforAll;
    private JLabel selectGrfic;
    private JLabel commentforAll;
    private MainInterface main;
}
